import { ElMessage } from "element-plus";
import router from "@/router";
import { post } from '@/utlis/http'
import store from "@/store";

export default {
  state() {
    return {
      users: {},//用户信息
    }
  },
  getters: {
    userInfo(state) {
      return state.users
    },
    permissionList(state) {
      return state.users.perms
    },
  },
  mutations: {
    userInfo(state, users) {
      state.users = users;
    },
    // 退出登录
    loginOut(state) {
      post(state, { _gp: "admin", _mt: "logout" }).then((res) => {
        let { errmsg, errno } = res.data;
        if (200 == errno) {
          state.users = {};//清空
          store.state.tags.dynamicTag = [{ path: "home", name: "home", meta: { title: "首页" } }]
          router.replace("/login");//跳转
        } else {
          ElMessage.success(errmsg);
        }
      })
    },
  },
  actions: {
    // 个人资料
    userInfo(context, users) {
      context.commit('userInfo', users)
    },
    // 退出登录
    loginOut(context) {
      context.commit('loginOut')
    },
  },
};
